﻿CREATE PROCEDURE [dbo].[state_Verify_CheckApproved]
@VerificationID int
AS
DECLARE @Count int
SELECT @Count = COUNT(*) 
FROM v_Loan_Verification LV
INNER JOIN t_VerificationSmart VS ON LV.LoanID = VS.LoanID
INNER JOIN v_State S ON VS.StatusID = S.ID AND LV.WorkFlowIndex <= S.WorkFlowIndex
WHERE VS.ID = @VerificationID AND LV.Checked = 0

IF @Count =  0 RETURN

IF @@TRANCOUNT > 0 ROLLBACK TRAN
RAISERROR ('All tasks must be finished before verification is approved.',16,1)
